//
//  accountBookDetailVC.m
//  CMAccountBook
//
//  Created by 王开政 on 2018/11/1.
//  Copyright © 2018年 王开政. All rights reserved.
//

#import "accountBookDetailVC.h"
#import "KAlteView.h"
@interface accountBookDetailVC ()<UITableViewDelegate,UITableViewDataSource>{

    KAlteView *alteview;
}
@property(nonatomic,strong)UITableView *Tab;

@property(nonatomic,strong)UIButton *editButton;

@property(nonatomic,strong)UIButton *deleteButton;

@property (nonatomic, strong) UIView *coverView;

@end

@implementation accountBookDetailVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor colorWithHexString:@"#ffffff"];
    [self navig];
    alteview = [[KAlteView alloc]initFrame:CGRectMake(63*kfit, 306*kfit, ScreenWidth - 63*2*kfit, 138*kfit)];
    alteview.titleLabel.text = @"确认删除?";
    alteview.contentLabel.text = @"删除数据后数据不可恢复!";
    [alteview.sureButton addTarget:self action:@selector(cancelPress) forControlEvents:UIControlEventTouchUpInside];
    [alteview.cancelButton addTarget:self action:@selector(cancelPress) forControlEvents:UIControlEventTouchUpInside];
    [alteview.sureButton setTitle:@"删除" forState:0];
    
    UIView *line = [[UIView alloc]initWithFrame:CGRectMake(ScreenWidth/2, ScreenHeight-SafeAreaTabbarHeight+20, 1, 20)];
    line.backgroundColor = [UIColor colorWithHexString:@"#f0f0f0"];
    
    [self.view addSubview:self.Tab];
    [self.view addSubview:self.editButton];
    [self.view addSubview:self.deleteButton];
    [self.view addSubview:line];
    [self.view addSubview:self.coverView];
    // Do any additional setup after loading the view.
}
#pragma mark-自定义导航区
-(void)navig{
    
    self.navigationController.interactivePopGestureRecognizer.enabled = YES;
    self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
    self.navigationController.navigationBarHidden=YES;
    __weak typeof(self) weakself = self;
    HomeNavigation*navView = [[HomeNavigation alloc]initWithTag:1 title:self.detailDic[@"name"] handler:^(UIButton *sender) {
        [weakself backPress];
    }];
    [self.view addSubview:navView];
    
}
-(void)backPress{
    
    [self.navigationController popViewControllerAnimated:YES];
    
    
}
-(UIView *)coverView{
    
    if (!_coverView) {
        
        _coverView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight )];
        _coverView.backgroundColor = [UIColor colorWithRed:127/255.0 green:127/255.0 blue:127/255.0 alpha:0.5];
        
        UITapGestureRecognizer *tapGesturRecognizer=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(cancelPress)];
        [_coverView addGestureRecognizer:tapGesturRecognizer];
        _coverView.hidden = YES;
        
        
    }
    
    
    return  _coverView;
}

-(void)cancelPress
{
    
    
    [alteview removeFromSuperview];
    [UIView animateWithDuration:0.5 animations:^{
//        self->alertView.frame = CGRectMake(0, ScreenHeight , ScreenWidth, 170);
        [self->alteview removeFromSuperview];
        self.coverView.hidden = YES;
    } completion:^(BOOL finished) {
        
        
        
    }];
    
    
}
-(UIButton *)editButton{
    if (!_editButton) {
        _editButton = [[UIButton alloc]initWithFrame:CGRectMake(0, ScreenHeight- SafeAreaTabbarHeight, ScreenWidth/2, SafeAreaTabbarHeight)];
        [_editButton setTitle:@"编辑" forState:0];
        [_editButton setTitleColor:[UIColor blackColor] forState:0];
        
    }
    return _editButton;
}
-(UIButton *)deleteButton{
    if (!_deleteButton) {
        _deleteButton = [[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth/2, ScreenHeight- SafeAreaTabbarHeight, ScreenWidth/2, SafeAreaTabbarHeight)];
        [_deleteButton setTitle:@"删除" forState:0];
        [_deleteButton addTarget:self action:@selector(deleteButtonPress) forControlEvents:UIControlEventTouchUpInside];
        [_deleteButton setTitleColor:[UIColor blackColor] forState:0];
        
    }
    return _deleteButton;
}
-(void)deleteButtonPress{
    
    [UIView animateWithDuration:0.5 animations:^{
        
        self.coverView.hidden = NO;
        [self.coverView addSubview:self->alteview];
        
    } completion:^(BOOL finished) {
        
    }];
}

-(UITableView *)Tab{
    
    if (!_Tab) {
        _Tab = [[UITableView alloc]initWithFrame:CGRectMake(0,SafeAreaTopHeight, ScreenWidth, ScreenHeight - SafeAreaTabbarHeight-SafeAreaTopHeight)];
        _Tab.backgroundColor = [UIColor colorWithHexString:@"#f5f5f5"];
        _Tab.delegate = self;
        _Tab.dataSource = self;
        //        self.myTab.scrollEnabled = NO;
        _Tab.showsVerticalScrollIndicator = NO;
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 50)];
        UILabel *lab = [[UILabel alloc]initWithFrame:CGRectMake(0, 10, ScreenWidth, 40)];
        lab.text = @"阿里云提供数据安全保障";
        lab.font = [UIFont systemFontOfSize:14*kfit];
        lab.textColor = [UIColor colorWithHexString:@"#999999"];
        lab.textAlignment = NSTextAlignmentCenter;
        [view addSubview:lab];
        //        _Tab.tableFooterView = view;
        //        _Tab.tableHeaderView = self.TabHeadView;
        _Tab.tableFooterView.backgroundColor = [UIColor colorWithHexString:@"#f5f5f5"];
        if(@available(iOS 11.0, *)){
            _Tab.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
            _Tab.estimatedRowHeight = 0;
            _Tab.estimatedSectionHeaderHeight = 0;
            _Tab.estimatedSectionFooterHeight = 0;
            
        }
        
    }
    
    return _Tab;
}
#pragma mark -设置cell横线左顶边
-(void)viewDidLayoutSubviews {
    if ([self.Tab respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.Tab setSeparatorInset:UIEdgeInsetsZero];
    }
    if ([self.Tab respondsToSelector:@selector(setLayoutMargins:)])  {
        [self.Tab setLayoutMargins:UIEdgeInsetsZero];
    }
}
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPat{
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]){
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
}
#pragma  make - UITableViewDataSource

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}



-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    
    return 4;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    
    if (!cell) {
        
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
        
    }
    //    cell.accessoryType =UITableViewCellAccessoryDisclosureIndicator;
//    cell.imageView.image = [UIImage imageNamed:@"我的摇钱桩购买"];
    cell.textLabel.textColor = [UIColor colorWithHexString:@"#9d9d9d"];
    cell.textLabel.font = [UIFont systemFontOfSize:14*kfit];
    
    cell.detailTextLabel.textColor = [UIColor colorWithHexString:@"#000000"];
    cell.detailTextLabel.font = [UIFont systemFontOfSize:14*kfit];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if (indexPath.row == 0) {
        cell.textLabel.text = @"金额";
        cell.detailTextLabel.text = self.detailDic[@"money"];
    }else if (indexPath.row == 1){
        cell.textLabel.text = @"类型";
        cell.detailTextLabel.text = self.detailDic[@"type"];
    }else if (indexPath.row == 2){
        cell.textLabel.text = @"日期";
        cell.detailTextLabel.text = self.detailDic[@"date"];
    }else if (indexPath.row == 3){
        cell.textLabel.text = @"备注";
        cell.detailTextLabel.text = self.detailDic[@"remark"];
    }
    
    return cell;
}

#pragma  make - UITableViewDelegate
//返回高度，计算不同高度cell 一定要用，否则会出现偏移
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    return 60;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *view =[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 35)];
//    view.backgroundColor = [UIColor colorWithHexString:@"#F6F6F8"];
//    UILabel *leftLabel = [[UILabel alloc]initWithFrame:CGRectMake(21*kfit, 0, ScreenWidth/2, 35)];
//    leftLabel.textColor = [UIColor colorWithHexString:@"#B7B7B7"];
//    leftLabel.font = [UIFont systemFontOfSize:10*kfit];
//    leftLabel.textAlignment = NSTextAlignmentLeft;
//    leftLabel.text =self.sectionArray[section][@"data"];
//
//    UILabel *rightLabel = [[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth/2 -21*kfit, 0, ScreenWidth/2, 35)];
//    rightLabel.textColor = [UIColor colorWithHexString:@"#B7B7B7"];
//    rightLabel.font = [UIFont systemFontOfSize:10*kfit];
//    rightLabel.textAlignment = NSTextAlignmentRight;
//    rightLabel.text =self.sectionArray[section][@"money"];
//
//    [view addSubview:leftLabel];
//    [view addSubview:rightLabel];
    
    return view;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
    return 0.01;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    
//    accountBookDetailVC *VC = [[accountBookDetailVC alloc]init];
//    VC.detailDic = self.sectionArray[indexPath.section][@"array"];
//    self.navigationController.navigationBarHidden=NO;
//    [VC setHidesBottomBarWhenPushed:YES];
//    [self.navigationController pushViewController:VC animated:YES];
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
